﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.Xml.Schema;

namespace nGSO.Config
{
    [Serializable]
    public class OptimizationTaskElement : ConfigurationElement, IXmlSerializable
    {
        [ConfigurationProperty("name", IsRequired = true, IsKey = true)]
        public string Name
        {
            get { return (string)base["name"]; }
            set { base["name"] = value; }
        }


        [ConfigurationProperty("function_body", IsRequired = true)]
        public string FunctionBody
        {
            get { return (string)base["function_body"]; }
            set { base["function_body"] = value; }
        }

        [ConfigurationProperty("population", IsRequired = true)]
        public int Population
        {
            get { return (int)base["population"]; }
            set { base["population"] = value; }
        }

        [ConfigurationProperty("max_iterations", IsRequired = true)]
        public int MaxIterations
        {
            get { return (int)base["max_iterations"]; }
            set { base["max_iterations"] = value; }
        }

        [ConfigurationProperty("space_size", IsRequired = true)]
        public int SpaceSize
        {
            get { return (int)base["space_size"]; }
            set { base["space_size"] = value; }
        }

        [ConfigurationProperty("sensor_range", IsRequired = true)]
        public double RadialSensorRange
        {
            get { return (double)base["sensor_range"]; }
            set { base["sensor_range"] = value; }
        }

        [ConfigurationProperty("optima", IsRequired = false)]
        public string EncodedOptima
        {
            get
            {
                return (string)base["optima"];
            }
            set
            {
                base["optima"] = value;
            }
        }

        protected override ConfigurationPropertyCollection Properties
        {
            get
            {
                return base.Properties;
            }
        }

        #region IXmlSerializable Members

        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return new XmlSchema();
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            this.DeserializeElement(reader, true);
        }

        public void WriteXml(System.Xml.XmlWriter writer)
        {
            this.SerializeElement(writer, true);
        }

        #endregion
    }
}
